package com.example.littleken.dialogtext;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn_alert,btn_datepicker,btn_progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        setlistener();
    }

    private void setlistener() {
        btn_alert.setOnClickListener(this);
        btn_datepicker.setOnClickListener(this);
        btn_progress.setOnClickListener(this);
    }

    private void initView() {
        btn_alert = (Button) findViewById(R.id.btn_alert);
        btn_datepicker = (Button) findViewById(R.id.btn_datepickerdialog);
        btn_progress = (Button) findViewById(R.id.btn_progressdialog);
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_alert:
                //Toast.makeText(MainActivity.this,"alert",Toast.LENGTH_SHORT).show();
                showAlertDialog();
                break;
            case R.id.btn_datepickerdialog:
                //Toast.makeText(MainActivity.this,"datepickerdialog",Toast.LENGTH_SHORT).show();
                showDatePickerDialog();
                break;
            case R.id.btn_progressdialog:
                //Toast.makeText(MainActivity.this,"progressdialog",Toast.LENGTH_SHORT).show();
                showProgressDialog();
                break;
        }
    }


    private void showAlertDialog() {
        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
        dialog.setTitle("欢迎");
        dialog.setMessage("欢迎使用本程序");
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "肯定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this,"肯定", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "否定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this,"肯定", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    private void showDatePickerDialog() {
        startActivity(new Intent(MainActivity.this,DataActivity.class));
    }

    private void showProgressDialog() {
        startActivity(new Intent(MainActivity.this,ProgressBarActivity.class));
    }



}
